﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.InteropServices;
using System.Text;
using System.Threading.Tasks;

namespace BrickAndBrick
{
    class WindowController
    {
        public static void SetWindowSize(int height = 844, int width = 450, string windowName = "砖了个砖")
        {
            IntPtr hWnd = FindWindow(null, windowName);
            RECT rect = new RECT();
            GetWindowRect(hWnd, ref rect);//获取窗口在屏幕上的坐标

            MoveWindow(hWnd, rect.Left, rect.Top, width, height, true); //锁定为1024*768分辨率
            Console.WriteLine(width + " " + height);
        }

        // 导入Windows API函数
        [DllImport("user32.dll", SetLastError = true)]
        static extern IntPtr FindWindow(string lpClassName, string lpWindowName);

        [DllImport("user32.dll")]
        [return: MarshalAs(UnmanagedType.Bool)]
        static extern bool GetWindowRect(IntPtr hWnd, ref RECT lpRect);

        [DllImport("user32.dll")]
        static extern void MoveWindow(IntPtr hWnd, int X, int Y, int nWidth, int nHeight, bool bRepaint);
        [StructLayout(LayoutKind.Sequential)]
        struct RECT //定位当前窗口位置
        {
            public int Left;
            public int Top;
            public int Right;
            public int Bottom;
        }
    }
}
